/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;



import gestion_chambes_hotel.Gestion_Chambes_Hotel;
import java.awt.Color;
import java.awt.HeadlessException;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.jdbc.JDBCCategoryDataset;

/**
 *
 * @author anas
 */
public class Reservation extends javax.swing.JInternalFrame {

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    private final Connection conn;
    private ResultSet rs=null;
    public Reservation() {
        initComponents();
        conn = gestion_chambes_hotel.Gestion_Chambes_Hotel.DB_Connection();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Pane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        E1 = new javax.swing.JLabel();
        CH1 = new javax.swing.JLabel();
        NP1 = new javax.swing.JLabel();
        Num_Chambre = new javax.swing.JComboBox();
        TXT_MESSAGE = new javax.swing.JLabel();
        montant = new javax.swing.JButton();
        Type_Chambre_Client = new javax.swing.JComboBox();
        Num_Personne = new javax.swing.JComboBox();
        E2 = new javax.swing.JLabel();
        NP2 = new javax.swing.JLabel();
        CH2 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        CIN_Rechercher = new javax.swing.JTextField();
        TXT_CIN = new javax.swing.JTextField();
        TXT_NOM = new javax.swing.JTextField();
        TXT_PRENOM = new javax.swing.JTextField();
        C1 = new javax.swing.JLabel();
        N1 = new javax.swing.JLabel();
        P1 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        C2 = new javax.swing.JLabel();
        N2 = new javax.swing.JLabel();
        P2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        RE1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        Notes = new javax.swing.JTextArea();
        DP1 = new javax.swing.JLabel();
        DR1 = new javax.swing.JLabel();
        DS1 = new javax.swing.JLabel();
        Date_Paiement_Client = new com.toedter.calendar.JDateChooser();
        Date_Reservation_Client = new com.toedter.calendar.JDateChooser();
        Date_Sortir_Client = new com.toedter.calendar.JDateChooser();
        TJ1 = new javax.swing.JLabel();
        Total_Jour = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        DP2 = new javax.swing.JLabel();
        DR2 = new javax.swing.JLabel();
        DS2 = new javax.swing.JLabel();
        TJ2 = new javax.swing.JLabel();
        RE2 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();

        setBorder(null);
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setMinimumSize(new java.awt.Dimension(894, 555));
        setPreferredSize(new java.awt.Dimension(894, 555));

        jPanel1.setLayout(null);

        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 51, 204)));
        jPanel3.setLayout(null);

        E1.setFont(new java.awt.Font("Abyssinica SIL", 1, 14)); // NOI18N
        E1.setForeground(new java.awt.Color(0, 0, 0));
        E1.setText("Etage du Chambre :");
        jPanel3.add(E1);
        E1.setBounds(30, 20, 160, 40);

        CH1.setFont(new java.awt.Font("Abyssinica SIL", 1, 14)); // NOI18N
        CH1.setForeground(new java.awt.Color(0, 0, 0));
        CH1.setText("N° Chambre :");
        jPanel3.add(CH1);
        CH1.setBounds(70, 190, 130, 40);

        NP1.setFont(new java.awt.Font("Abyssinica SIL", 1, 14)); // NOI18N
        NP1.setForeground(new java.awt.Color(0, 0, 0));
        NP1.setText("Nombre des Personnes :");
        jPanel3.add(NP1);
        NP1.setBounds(10, 120, 190, 30);

        Num_Chambre.setToolTipText("");
        Num_Chambre.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                Num_ChambreMouseReleased(evt);
            }
        });
        Num_Chambre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Num_ChambreActionPerformed(evt);
            }
        });
        jPanel3.add(Num_Chambre);
        Num_Chambre.setBounds(210, 200, 60, 24);

        TXT_MESSAGE.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jPanel3.add(TXT_MESSAGE);
        TXT_MESSAGE.setBounds(240, 270, 50, 40);

        montant.setBackground(new java.awt.Color(204, 255, 204));
        montant.setText("Afficher le Montant!");
        montant.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                montantActionPerformed(evt);
            }
        });
        jPanel3.add(montant);
        montant.setBounds(10, 280, 180, 25);

        Type_Chambre_Client.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2" }));
        jPanel3.add(Type_Chambre_Client);
        Type_Chambre_Client.setBounds(210, 30, 60, 24);

        Num_Personne.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4" }));
        Num_Personne.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Num_PersonneMouseClicked(evt);
            }
        });
        Num_Personne.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Num_PersonneActionPerformed(evt);
            }
        });
        jPanel3.add(Num_Personne);
        Num_Personne.setBounds(210, 120, 60, 24);

        E2.setText("الطابق :");
        jPanel3.add(E2);
        E2.setBounds(350, 30, 70, 30);

        NP2.setText("عدد الاشخاص :");
        jPanel3.add(NP2);
        NP2.setBounds(340, 110, 110, 40);

        CH2.setText("رقم الغرفة :");
        jPanel3.add(CH2);
        CH2.setBounds(345, 190, 90, 40);

        jLabel25.setText("DH");
        jPanel3.add(jLabel25);
        jLabel25.setBounds(280, 270, 20, 50);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Accueil/wallhaven-19788.jpg"))); // NOI18N
        jPanel3.add(jLabel2);
        jLabel2.setBounds(0, 0, 470, 340);

        jPanel1.add(jPanel3);
        jPanel3.setBounds(420, 90, 460, 340);

        CIN_Rechercher.setText("Dernier Client Ajouté ....");
        CIN_Rechercher.setBorder(null);
        CIN_Rechercher.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                CIN_RechercherMouseReleased(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                CIN_RechercherMouseClicked(evt);
            }
        });
        CIN_Rechercher.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CIN_RechercherActionPerformed(evt);
            }
        });
        CIN_Rechercher.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                CIN_RechercherKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                CIN_RechercherKeyPressed(evt);
            }
        });
        jPanel1.add(CIN_Rechercher);
        CIN_Rechercher.setBounds(110, 70, 180, 30);

        TXT_CIN.setEditable(false);
        TXT_CIN.setBackground(new java.awt.Color(255, 255, 255));
        TXT_CIN.setBorder(null);
        jPanel1.add(TXT_CIN);
        TXT_CIN.setBounds(100, 170, 180, 30);

        TXT_NOM.setEditable(false);
        TXT_NOM.setBackground(new java.awt.Color(255, 255, 255));
        TXT_NOM.setBorder(null);
        jPanel1.add(TXT_NOM);
        TXT_NOM.setBounds(100, 250, 180, 30);

        TXT_PRENOM.setEditable(false);
        TXT_PRENOM.setBackground(new java.awt.Color(255, 255, 255));
        TXT_PRENOM.setBorder(null);
        jPanel1.add(TXT_PRENOM);
        TXT_PRENOM.setBounds(100, 340, 180, 30);

        C1.setFont(new java.awt.Font("Abyssinica SIL", 1, 14)); // NOI18N
        C1.setForeground(new java.awt.Color(0, 0, 0));
        C1.setText("CIN :");
        jPanel1.add(C1);
        C1.setBounds(30, 170, 50, 22);

        N1.setFont(new java.awt.Font("Abyssinica SIL", 1, 14)); // NOI18N
        N1.setForeground(new java.awt.Color(0, 0, 0));
        N1.setText("Nom :");
        jPanel1.add(N1);
        N1.setBounds(30, 250, 50, 30);

        P1.setFont(new java.awt.Font("Abyssinica SIL", 1, 14)); // NOI18N
        P1.setForeground(new java.awt.Color(0, 0, 0));
        P1.setText("Prenom :");
        jPanel1.add(P1);
        P1.setBounds(10, 340, 80, 30);

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/txt1.png"))); // NOI18N
        jPanel1.add(jLabel11);
        jLabel11.setBounds(90, 160, 240, 50);

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/txt1.png"))); // NOI18N
        jPanel1.add(jLabel12);
        jLabel12.setBounds(90, 240, 230, 50);

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/txt1.png"))); // NOI18N
        jPanel1.add(jLabel14);
        jLabel14.setBounds(90, 320, 230, 70);

        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/txt1.png"))); // NOI18N
        jPanel1.add(jLabel17);
        jLabel17.setBounds(100, 60, 250, 50);

        C2.setText("الرقم الوطني :");
        jPanel1.add(C2);
        C2.setBounds(320, 160, 110, 40);

        N2.setText("الاسم العائلي :");
        jPanel1.add(N2);
        N2.setBounds(320, 245, 100, 40);

        P2.setText("الاسم الشخصي :");
        jPanel1.add(P2);
        P2.setBounds(311, 335, 110, 40);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Accueil/wallhaven-19788.jpg"))); // NOI18N
        jPanel1.add(jLabel1);
        jLabel1.setBounds(0, 0, 910, 520);

        Pane1.addTab("Details", jPanel1);

        jPanel2.setAutoscrolls(true);
        jPanel2.setLayout(null);

        RE1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/Remarques.png"))); // NOI18N
        jPanel2.add(RE1);
        RE1.setBounds(212, 281, 83, 14);

        Notes.setColumns(20);
        Notes.setRows(5);
        jScrollPane1.setViewportView(Notes);

        jPanel2.add(jScrollPane1);
        jScrollPane1.setBounds(440, 227, 320, 138);

        DP1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/Date de Paiement.png"))); // NOI18N
        jPanel2.add(DP1);
        DP1.setBounds(170, 20, 126, 19);

        DR1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/Date de Réservation.png"))); // NOI18N
        jPanel2.add(DR1);
        DR1.setBounds(150, 80, 143, 13);

        DS1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/Date  de Sortir.png"))); // NOI18N
        jPanel2.add(DS1);
        DS1.setBounds(190, 130, 106, 13);

        Date_Paiement_Client.setDateFormatString("yyyy-MM-dd");
        jPanel2.add(Date_Paiement_Client);
        Date_Paiement_Client.setBounds(440, 22, 188, 27);

        Date_Reservation_Client.setDateFormatString("yyyy-MM-dd");
        jPanel2.add(Date_Reservation_Client);
        Date_Reservation_Client.setBounds(440, 75, 188, 27);

        Date_Sortir_Client.setDateFormatString("yyyy-MM-dd");
        Date_Sortir_Client.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                Date_Sortir_ClientMouseReleased(evt);
            }
        });
        jPanel2.add(Date_Sortir_Client);
        Date_Sortir_Client.setBounds(440, 128, 188, 28);

        TJ1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/Total du Jours.png"))); // NOI18N
        jPanel2.add(TJ1);
        TJ1.setBounds(192, 182, 103, 15);

        Total_Jour.setText("0");
        Total_Jour.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                Total_JourMouseReleased(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Total_JourMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                Total_JourMouseEntered(evt);
            }
        });
        Total_Jour.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Total_JourActionPerformed(evt);
            }
        });
        jPanel2.add(Total_Jour);
        Total_Jour.setBounds(440, 182, 188, 27);

        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Buttons/Enregistrer_Client.png"))); // NOI18N
        jLabel15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel15MouseReleased(evt);
            }
        });
        jPanel2.add(jLabel15);
        jLabel15.setBounds(570, 420, 136, 41);

        jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Buttons/Annuler.png"))); // NOI18N
        jPanel2.add(jLabel18);
        jLabel18.setBounds(360, 420, 137, 41);

        DP2.setFont(new java.awt.Font("Amiri", 1, 15)); // NOI18N
        DP2.setText("تاريخ الاداء :");
        jPanel2.add(DP2);
        DP2.setBounds(670, 20, 80, 30);

        DR2.setFont(new java.awt.Font("Amiri", 1, 15)); // NOI18N
        DR2.setText("تاريخ الحجز :");
        jPanel2.add(DR2);
        DR2.setBounds(670, 75, 52, 30);

        DS2.setFont(new java.awt.Font("Amiri", 1, 15)); // NOI18N
        DS2.setText("تاريخ الخروج :");
        jPanel2.add(DS2);
        DS2.setBounds(670, 125, 67, 30);

        TJ2.setFont(new java.awt.Font("Amiri", 1, 15)); // NOI18N
        TJ2.setText("مجموع الايام :");
        jPanel2.add(TJ2);
        TJ2.setBounds(670, 180, 62, 30);

        RE2.setFont(new java.awt.Font("Amiri", 1, 15)); // NOI18N
        RE2.setText("ملاحظات :");
        jPanel2.add(RE2);
        RE2.setBounds(780, 265, 80, 30);

        jLabel20.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Accueil/wallhaven-19788.jpg"))); // NOI18N
        jPanel2.add(jLabel20);
        jLabel20.setBounds(0, 0, 890, 510);

        Pane1.addTab("Reservation Details", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Pane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Pane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    
    
    public void Traduire()
    {
    
        C1.setVisible(false);
        N1.setVisible(false);
        P1.setVisible(false);
        E1.setVisible(false);
        NP1.setVisible(false);
        CH1.setVisible(false);
        montant.setText("ثمن لغرفة");
        DR1.setVisible(true);
        DP1.setVisible(true);
        DS1.setVisible(true);
        RE1.setVisible(true);
        TJ1.setVisible(true);
        
        C2.setVisible(true);
        N2.setVisible(true);
        P2.setVisible(true);
        E2.setVisible(true);
        NP2.setVisible(true);
        CH2.setVisible(true);
        CIN_Rechercher.setText("الرقم الوطني");
        DR2.setVisible(true);
        DP2.setVisible(true);
        DS2.setVisible(true);
        RE2.setVisible(true);
        TJ2.setVisible(true);
    }
    
    public void Visibility()
    {
    
        C2.setVisible(false);
        N2.setVisible(false);
        P2.setVisible(false);
        E2.setVisible(false);
        NP2.setVisible(false);
        CH2.setVisible(false);
        DR2.setVisible(false);
        DP2.setVisible(false);
        DS2.setVisible(false);
        RE2.setVisible(false);
        TJ2.setVisible(false);
    }
    
    
    
    private void obtenir_info_chambre()
    {
        int num_cham=0;
        try {
            
            String sql0="select * from chambre where ETAGE_CHAMBRE=? and TYPE_CHAMBRE=? and STATUS_CHAMBRE=?";
            
            PreparedStatement ps0 = conn.prepareStatement(sql0);
            ps0.setInt(1, Integer.parseInt(Type_Chambre_Client.getSelectedItem().toString()));
            ps0.setInt(2, Integer.parseInt(Num_Personne.getSelectedItem().toString()));
            ps0.setString(3, "non");
            ResultSet rs0 ;
            rs0=ps0.executeQuery();
            Num_Chambre.removeAllItems();
            while(rs0.next())
                {   
                    num_cham =rs0.getInt("NUMERO_CHAMBRE");
                    Num_Chambre.addItem(num_cham);
                    
                }
            
            
        } catch (SQLException | NumberFormatException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
            
    }
    private void Obtenir_le_montant()
    {
    
        
        
            try{ 
                    String sql_montant = "select * from montant where ETAGE_CHAMBRE=? and TYPE_CHAMBRE=? and NUM_CHAMBRE=?";
                    PreparedStatement ps_montant=conn.prepareStatement(sql_montant);
                    ps_montant.setInt(1,Integer.parseInt(Type_Chambre_Client.getSelectedItem().toString()));
                    ps_montant.setInt(2,Integer.parseInt(Num_Personne.getSelectedItem().toString()));
                    ps_montant.setInt(3,Integer.parseInt(Num_Chambre.getSelectedItem().toString()));

                    rs=ps_montant.executeQuery();
                    while(rs.next())
                        {

                            int montant =rs.getInt("MONTANT_CHAMBRE");
                            TXT_MESSAGE.setText(+montant+"");
                            System.out.println(montant);
                        }

            }catch(SQLException | NumberFormatException e)
             {
                 JOptionPane.showMessageDialog(null, e.getMessage());

             }
    
    }
        
        //MONTANT_FACTURE
    private int inserer_total()
    {
        int montant=Integer.parseInt(TXT_MESSAGE.getText());
        int total_jour=Integer.parseInt(Total_Jour.getText());
        int final_total=montant*total_jour;
        return final_total;
        
    
    }
     private void Get_Info_Reservation(){
       try{
           
           
           //insertion des infos de reservation 
           
           String sql0 ="insert into reservation(CIN_CLIENT,ETAGE_CHAMBRE,NUM_CHAMBRE,TYPE_CHAMBRE) values(?,?,?,?)";
           
                        PreparedStatement ps1 = conn.prepareStatement(sql0); 
                        ps1.setString(1,CIN_Rechercher.getText());
                        ps1.setInt(2, Integer.parseInt(Type_Chambre_Client.getSelectedItem().toString()));
                        ps1.setInt(3, Integer.parseInt( Num_Chambre.getSelectedItem().toString()));
                        ps1.setInt(4, Integer.parseInt( Num_Personne.getSelectedItem().toString()));
                        
            String sql_chambre="update chambre set STATUS_CHAMBRE=? where NUMERO_CHAMBRE=?";            
                        PreparedStatement ps0 = conn.prepareStatement(sql_chambre); 
                        ps0.setString(1, "oui");
                        ps0.setInt(2, Integer.parseInt( Num_Chambre.getSelectedItem().toString()));
            //insertion de paiement          
                        
           String sql1="insert into paiement(CIN_CLIENT,DATE_PAIEMENT,PRE_JOUR_OCCU,DER_JOUR_OCCU,TOTAL_JOUR,NOTES,MONTANT_FACTURE) values(?,?,?,?,?,?,?)";
           PreparedStatement ps2 = conn.prepareStatement(sql1); 
                        ps2.setString(1,CIN_Rechercher.getText());
                        ps2.setString(2,((JTextField)Date_Paiement_Client.getDateEditor().getUiComponent()).getText());
                        ps2.setString(3, ((JTextField)Date_Reservation_Client.getDateEditor().getUiComponent()).getText());
                        ps2.setString(4, ((JTextField)Date_Sortir_Client.getDateEditor().getUiComponent()).getText());
                        ps2.setString(5, Total_Jour.getText());
                        ps2.setString(6, Notes.getText());
                        ps2.setInt(7,inserer_total());
                        
                        //execution
                        ps1.executeUpdate();
                        ps0.executeUpdate();
                        ps2.executeUpdate();
                        
                        
                        //JOptionPane.showMessageDialog(null,"reservation avec succes !");
       } 
       catch(SQLException | NumberFormatException | HeadlessException e)
       {
           JOptionPane.showMessageDialog(null,"Echec De reservation !"+e.getMessage());
       }
                      
    }
     
    private void Update_Info_Reservation(){
       try{
           
           
           //insertion des infos de reservation 
           String cin=TXT_CIN.getText();
           String sql0 ="update  reservation set CIN_CLIENT=?,ETAGE_CHAMBRE=?,NUM_CHAMBRE=?,TYPE_CHAMBRE=?) where CIN_CLIENT=?";
           
                        PreparedStatement ps1 = conn.prepareStatement(sql0); 
                        ps1.setString(1,CIN_Rechercher.getText());
                        ps1.setInt(2, Integer.parseInt(Type_Chambre_Client.getSelectedItem().toString()));
                        ps1.setInt(3, Integer.parseInt( Num_Chambre.getSelectedItem().toString()));
                        ps1.setInt(4, Integer.parseInt( Num_Personne.getSelectedItem().toString()));
                        ps1.setString(5, cin);
            String sql_chambre="update chambre set STATUS_CHAMBRE=? where NUMERO_CHAMBRE=?";            
                        PreparedStatement ps0 = conn.prepareStatement(sql_chambre); 
                        ps0.setString(1, "oui");
                        ps0.setInt(2, Integer.parseInt( Num_Chambre.getSelectedItem().toString()));
            //insertion de paiement          
                        
           String sql1="update  paiement set CIN_CLIENT=?,DATE_PAIEMENT=?,PRE_JOUR_OCCU=?,DER_JOUR_OCCU=?,TOTAL_JOUR=?,NOTES=?,MONTANT_FACTURE=? where CIN_CLIENT=?";
           PreparedStatement ps2 = conn.prepareStatement(sql1); 
                        ps2.setString(1,CIN_Rechercher.getText());
                        ps2.setString(2,((JTextField)Date_Paiement_Client.getDateEditor().getUiComponent()).getText());
                        ps2.setString(3, ((JTextField)Date_Reservation_Client.getDateEditor().getUiComponent()).getText());
                        ps2.setString(4, ((JTextField)Date_Sortir_Client.getDateEditor().getUiComponent()).getText());
                        ps2.setString(5, Total_Jour.getText());
                        ps2.setString(6, Notes.getText());
                        ps2.setInt(7,inserer_total());
                        ps2.setString(8, cin);
                        
                        //execution
                        ps1.executeUpdate();
                        ps0.executeUpdate();
                        ps2.executeUpdate();
                        
                        
                        JOptionPane.showMessageDialog(null,"reservation avec succes !");
       } 
       catch(SQLException | NumberFormatException | HeadlessException e)
       {
           JOptionPane.showMessageDialog(null,"Echec De reservation !"+e.getMessage());
       }
                      
    }
    
   private void Get_Info_Client(){
       
       
                try{
                    
                        String sql="SELECT * FROM client where CIN_CLIENT=?";
                        PreparedStatement pst = conn.prepareStatement(sql);
                        pst.setString(1,CIN_Rechercher.getText());
                        ResultSet res=pst.executeQuery();
                        if(res.next()){
                          String nom=res.getString("NOM");
                          String prenom=res.getString("PRENOM");
                          String cin=res.getString("CIN_CLIENT");

                          TXT_CIN.setText(cin);
                          TXT_NOM.setText(nom);
                          TXT_PRENOM.setText(prenom);
                          TXT_MESSAGE.setText("");
                        } else {
                            TXT_MESSAGE.setForeground(Color.red);
                            TXT_MESSAGE.setText("Client N'existe Pas !");
                        }

                }catch(SQLException e){

                    JOptionPane.showMessageDialog(null,"Echec De La Selection de Client !"+e.getMessage());
                        }
                }
    
    
    
    private void CIN_RechercherKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CIN_RechercherKeyPressed
        if(evt.getKeyCode()==KeyEvent.VK_ENTER){
            Get_Info_Client();
        }
    }//GEN-LAST:event_CIN_RechercherKeyPressed

    private void CIN_RechercherKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CIN_RechercherKeyTyped
        if(CIN_Rechercher.getText().equals("")){
            TXT_CIN.setText("");
            TXT_NOM.setText("");
            TXT_PRENOM.setText("");
            TXT_MESSAGE.setText("");
        }
    }//GEN-LAST:event_CIN_RechercherKeyTyped
    
    
    private void getTotal(){
    
        Date date1= (Date) Date_Reservation_Client.getDate();
        Date  dsc=(Date) Date_Sortir_Client.getDate();
        
        long differenceInMilliseconds = dsc.getTime() - date1.getTime(); 
        int differenceInDays = (int)differenceInMilliseconds/(1000*60*60*24);
        
        
        String toLong=Integer.toString(differenceInDays);
        Total_Jour.setText(toLong);
    
    }
    
    private void Total_JourMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Total_JourMouseClicked

      //getTotal();
        
        

    }//GEN-LAST:event_Total_JourMouseClicked
    
    public void nombre_jours() {
        
        
    }
    
    
    private void Total_JourActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Total_JourActionPerformed
        
        Calc_Date();
    }//GEN-LAST:event_Total_JourActionPerformed

    private void jLabel15MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel15MouseReleased
        Update_Info_Reservation();
        
    }//GEN-LAST:event_jLabel15MouseReleased

    private void CIN_RechercherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CIN_RechercherActionPerformed
        
    }//GEN-LAST:event_CIN_RechercherActionPerformed

    private void CIN_RechercherMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CIN_RechercherMouseReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_CIN_RechercherMouseReleased

    private void CIN_RechercherMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CIN_RechercherMouseClicked
        
        CIN_Rechercher.setText("");
        /*
        try {
            
            CIN_Rechercher.setText("");
            String sql_Dernier="select * from DERNIER_CLIENT";
            PreparedStatement ps_Der = conn.prepareStatement(sql_Dernier);
            
            String cin_der=rs.getString("CIN_CLIENT");
            while(rs.next()){
                
                CIN_Rechercher.setText(cin_der);
            }
            
            
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
        */
    }//GEN-LAST:event_CIN_RechercherMouseClicked
    
   
    
    private void Num_ChambreMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Num_ChambreMouseReleased
        obtenir_info_chambre();
    }//GEN-LAST:event_Num_ChambreMouseReleased

    private void Num_ChambreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Num_ChambreActionPerformed
        
        
    }//GEN-LAST:event_Num_ChambreActionPerformed

    private void montantActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_montantActionPerformed
        Obtenir_le_montant();
    }//GEN-LAST:event_montantActionPerformed

    private void Total_JourMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Total_JourMouseEntered
        //getTotal();
    }//GEN-LAST:event_Total_JourMouseEntered

    private void Num_PersonneMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Num_PersonneMouseClicked
        obtenir_info_chambre();
    }//GEN-LAST:event_Num_PersonneMouseClicked

    private void Date_Sortir_ClientMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Date_Sortir_ClientMouseReleased
        Get_Info_Reservation();
        Calc_Date();
    }//GEN-LAST:event_Date_Sortir_ClientMouseReleased

    private void Total_JourMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Total_JourMouseReleased
        
    }//GEN-LAST:event_Total_JourMouseReleased

    private void Num_PersonneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Num_PersonneActionPerformed
        obtenir_info_chambre();
    }//GEN-LAST:event_Num_PersonneActionPerformed
   
  
    private void Calc_Date()
        {
            try{
        String cin=TXT_CIN.getText();
        
         
        
        Statement st = conn.createStatement();
 
        st = conn.createStatement();
        ResultSet rs = st.executeQuery(" Select DATEDIFF(DER_JOUR_OCCU,PRE_JOUR_OCCU)from paiement AS DIFF where CIN_CLIENT='"+cin+"'");
         
             while (rs.next()) {
                  String name = rs.getString(1);
 
                  Total_Jour.setText(name);
 
                }
            
        
            }catch(Exception e)
                {
                    System.out.println(e.getMessage());
                }
        }
        
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel C1;
    private javax.swing.JLabel C2;
    private javax.swing.JLabel CH1;
    private javax.swing.JLabel CH2;
    private javax.swing.JTextField CIN_Rechercher;
    private javax.swing.JLabel DP1;
    private javax.swing.JLabel DP2;
    private javax.swing.JLabel DR1;
    private javax.swing.JLabel DR2;
    private javax.swing.JLabel DS1;
    private javax.swing.JLabel DS2;
    protected static com.toedter.calendar.JDateChooser Date_Paiement_Client;
    protected static com.toedter.calendar.JDateChooser Date_Reservation_Client;
    protected static com.toedter.calendar.JDateChooser Date_Sortir_Client;
    private javax.swing.JLabel E1;
    private javax.swing.JLabel E2;
    private javax.swing.JLabel N1;
    private javax.swing.JLabel N2;
    private javax.swing.JLabel NP1;
    private javax.swing.JLabel NP2;
    protected static javax.swing.JTextArea Notes;
    private javax.swing.JComboBox Num_Chambre;
    private javax.swing.JComboBox Num_Personne;
    private javax.swing.JLabel P1;
    private javax.swing.JLabel P2;
    private javax.swing.JTabbedPane Pane1;
    private javax.swing.JLabel RE1;
    private javax.swing.JLabel RE2;
    private javax.swing.JLabel TJ1;
    private javax.swing.JLabel TJ2;
    private javax.swing.JTextField TXT_CIN;
    private javax.swing.JLabel TXT_MESSAGE;
    private javax.swing.JTextField TXT_NOM;
    private javax.swing.JTextField TXT_PRENOM;
    private javax.swing.JTextField Total_Jour;
    private javax.swing.JComboBox Type_Chambre_Client;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton montant;
    // End of variables declaration//GEN-END:variables
}
